package com.ymatou.iapi.login.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.login.parameter.*;
import com.ymatou.iapi.login.service.*;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.Now;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.data.LoginSafeConfiguration;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.LoginLog;
import com.ymttest.database.mongo.MongoLoginHistoryWapper;
import com.ymttest.database.mongo.ULC201406Bean;
import com.ymttest.database.mongo.ULC201406Wapper;
import com.ymttest.database.mongo.YmatouBlacklistUserWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LoginHistoryWapper;
import com.ymttest.database.sqlwapper.UserSafeWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
*APP端设备认证接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeviceAuthStatusRequestDto{
	private static DeviceAuthStatusRequestDtoBean deviceauthstatusrequestdtoBean;
	private static DeviceAuthStatusRequestDtoCall deviceauthstatusrequestdtoCall;
	private static ULC201406Wapper userWapper;
	private static UserSafeWapper authWapper;
	private static YmatouBlacklistUserWapper blackLisWapper;
	private static MongoLoginHistoryWapper mloginHistoryWapper;
	private static final String SOURCETYPE = "app";
	private static final boolean DELETELOGINHISTORY = true;
	
	@BeforeClass
	public static void setUp() throws Exception {
		Logger.createResultFile("APP端设备认证接口");
		userWapper = new ULC201406Wapper();
		authWapper = new UserSafeWapper();
		blackLisWapper = new YmatouBlacklistUserWapper();
		mloginHistoryWapper = new MongoLoginHistoryWapper();
	}

	@Before
	public void caseUp() {
		deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
		deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() throws Throwable {
		Logger.generateResult(deviceauthstatusrequestdtoCall.getOpurl());
		userWapper.close();
		authWapper.close();
		blackLisWapper.close();
		mloginHistoryWapper.close();
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	public void config() throws InterruptedException {
		UserSafeWapper userSafeWapper = new UserSafeWapper();
		// 默认风控开关 dimension_strategy:checkOtherUserTypeLoginAuth=true
		userSafeWapper.updateRiskStrategyStatus(2, "DefaultSafeVerifyStrategy");
		// 买家设备号黑名单 dimension_strategy:deviceIdAllowNull=true
		userSafeWapper.updateRiskStrategyStatus(2, "BuyerOftenDeviceIdVerifyStrategy");
		// 买家ip区域认证(买家是否在此区域认证过)
		userSafeWapper.updateRiskStrategyStatus(2, "BuyerIpAreaVerifyStrategy");
		
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_001() {
		Logger.start(true,"设备第一次登陆时认证失败，再次认证成功");
		try {
			Logger.comment("前置条件准备");
			String ip2 =TestDataManager.getRandomIp();
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId=uc.getUserid();
			String loginId =urb.getLoginId();
			String deviceId = urb.getDeviceId();
			String clientId = deviceId+"client";
//			int userId = 4460;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkDeviceLoginHistory(deviceId,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			
			Logger.comment("如果此设备已认证过，先进行删除");
			authWapper.deleteDeviceData(userId, deviceId);
			
			Logger.comment("设备登陆，AUTH_DEVICE_OPEN状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN);
			Logger.comment("设备登陆，isAppAppDeviceOpen状态是:"+LoginSafeConfiguration.isAppAppDeviceOpen);
			JUserCallService.login(loginId, "123456a", "app", urb.getClientIp(), deviceId);
			Thread.sleep(1000);
			Map<String, Object> deviceAuth = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyNotNull(deviceAuth, "认证区域认证信息被写入数据库");
			//这里需要看风控开关
//			Logger.verifyEquals(0, deviceAuth.get("AuthStatus"), "验证认证状态为未认证");
			
			Logger.comment("第一次认证失败");
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(loginId);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(false);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			LoginSafeConfiguration.checkAuthStatus(false, deviceauthstatusrequestdtoCall);
			
			Logger.comment("第二次认证成功");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(loginId);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			
			Thread.sleep(3000);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = JUserCallService.login(loginId, "123456a", "app",ip2, deviceId);
			Logger.verifyEquals("true", lac2.getString("Success"), "验证登陆成功");
			
			
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> deviceAuth2 = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyEquals(200, deviceAuth2.get("AuthStatus"), "验证认证信息成功");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class,Now.class})
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_002() {
		Logger.start(true,"使用Token失效的设备登陆，再次认证成功");
		try {
			Logger.comment("修改token最后认证时间为100天前");
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId=uc.getUserid();
			String loginId =urb.getLoginId();
			String deviceId = urb.getDeviceId();
			checkDeviceLoginHistory(deviceId,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			authWapper.updateTokenUpdateTime(userId, deviceId, YMTDateUtil.getBeforeOrNextDay(-100));
			
			Logger.comment("设备登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setPas("123456a");
			lab.setClientIp("1.1.90.1");
			lab.setSourceType(SOURCETYPE);
			lab.setDeviceId(deviceId);
			lac.setData(lab);
			lac.callService();
			
			Logger.comment("第一次认证失败");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp("1.1.90.1");
			deviceauthstatusrequestdtoBean.setLoginId(loginId);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(false);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lac2.setData(lab);
			lac2.callService();
			
			authWapper.updateTokenUpdateTime(userId, deviceId, YMTDateUtil.getBeforeOrNextDay(-10));
			Logger.comment("第二次认证成功");
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp("1.1.90.1");
			deviceauthstatusrequestdtoBean.setLoginId(loginId);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("true", lac3.getString("Success"), "验证登陆成功");
			
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> deviceAuth2 = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyEquals(200, deviceAuth2.get("AuthStatus"), "验证认证信息成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_003() {
		Logger.start(true,"黑名单设备第一次认证失败后，再次认证成功");
		try {
			
			String deviceId = TestDataManager.getRandomUUID().toString();
			String clientId = deviceId+"client";
			checkDeviceLoginHistory(deviceId,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			
			
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			urb.setDeviceId(deviceId);
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId=uc.getUserid();
			String loginId =urb.getLoginId();
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			
			
			Logger.comment("添加设备黑名单");
			blackLisWapper.saveData(deviceId, YMTDateUtil.getDateForMongoFormat(-1, 0, 0), YMTDateUtil.getDateForMongoFormat(-1, 0, 0),
					YMTDateUtil.getDateForMongoFormat(1, 0, 0), false, 1);
			Logger.comment("设备登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setPas("123456a");
			lab.setClientIp("1.1.90.1");
			lab.setSourceType(SOURCETYPE);
			lab.setDeviceId(deviceId);
			lab.setClientId(clientId);
			lac.setData(lab);
			lac.callService();
//			LoginSafeConfiguration.checkLoginStatusWithBlackIp(lac, false, null);
			Logger.verifyEquals("false", lac.getString("Success"), "验证登陆成功");
			
			Logger.comment("第一次认证失败");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp("1.1.90.1");
			deviceauthstatusrequestdtoBean.setLoginId(loginId);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(false);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();	
//			LoginSafeConfiguration.checkAuthStatus(false, deviceauthstatusrequestdtoCall);
			
			Logger.comment("设备登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthCall lac2 = new LoginAuthCall();
			lac2.setData(lab);
			lac2.callService();
			Logger.verifyEquals("false", lac.getString("Success"), "验证登陆成功");
//			LoginSafeConfiguration.checkLoginStatusWithBlackIp(lac, false, null);
			
			Logger.comment("第二次认证成功");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp("1.1.90.1");
			deviceauthstatusrequestdtoBean.setLoginId(loginId);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			
			blackLisWapper.deleteData(deviceId);
			
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("true", lac3.getString("Success"), "验证登陆成功");
			
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> deviceAuth2 = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyEquals(200, deviceAuth2.get("AuthStatus"), "验证认证信息成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_004() {
		Logger.start(true,"注册无ip,app用户换IP区域登入风控后调用认证成功,修改ip和设备认证为200");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip=TestDataManager.getRandomIp();
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			urb.setClientIp(null);
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId=uc.getUserid();
			String UserName = urb.getLoginId();
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<LoginLog> list=new JUserWapper().selectLastLoginLogByUid(UserId);
			Logger.verifyEquals(1, list.size(), "验证loginlog表记录");
			String did=TestDataManager.getRandomUUID().toString();
			Logger.comment("开始登陆认证");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lab.setDeviceId(did);
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			DeviceAuthStatusRequestDtoBean deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			DeviceAuthStatusRequestDtoCall deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setDeviceId(did);
			deviceauthstatusrequestdtoBean.setIp(ip);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource("app");
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			Logger.verifyEquals("true", deviceauthstatusrequestdtoCall.getString("Success"), "验证Success");
			Thread.sleep(2000);
			Map<String, Object> deviceAuth2 = authWapper.getDeviceAuthByUserIdAndDeviceId(UserId, did).get(0);
			Logger.verifyEquals(200, deviceAuth2.get("AuthStatus"), "验证认证信息成功");	
			Map<String, Object> ipAuth = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
			Logger.verifyNotNull(ipAuth, "认证区域认证信息被写入数据库");
			Logger.verifyEquals(200, ipAuth.get("AuthStatus"), "验证认证状态为认证");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_005() {
		Logger.start(true,"传入TokenSource为app用户注册成功JIRACONN-2123");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip =TestDataManager.getRandomIp();
			String ip2 =TestDataManager.getRandomIp();
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId=uc.getUserid();
			String UserName=  urb.getLoginId();
			String deviceId = urb.getDeviceId();
			String clientId = deviceId+"client";
//			int userId = 4460;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkDeviceLoginHistory(deviceId,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			
			Logger.comment("如果此设备已认证过，先进行删除");
			authWapper.deleteDeviceData(userId, deviceId);
			
			Logger.comment("设备登陆，AUTH_DEVICE_OPEN状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN);
			Logger.comment("设备登陆，isAppAppDeviceOpen状态是:"+LoginSafeConfiguration.isAppAppDeviceOpen);
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setClientIp(ip2);
			lab.setSourceType(SOURCETYPE);
			lab.setDeviceId(deviceId);
			lab.setClientId(clientId);
			lac.setData(lab);
			lac.callService();
			Thread.sleep(1000);
			Map<String, Object> deviceAuth = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyNotNull(deviceAuth, "认证区域认证信息被写入数据库");
			//这里需要看风控开关
//			Logger.verifyEquals(0, deviceAuth.get("AuthStatus"), "验证认证状态为未认证");
			
			Logger.comment("第一次认证失败");
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(false);
			deviceauthstatusrequestdtoBean.setTokenSource("app");
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			LoginSafeConfiguration.checkAuthStatus(false, deviceauthstatusrequestdtoCall);
			
			Logger.comment("第二次认证成功");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoBean.setTokenSource("app");
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			String Sign=deviceauthstatusrequestdtoCall.getJsonObject().get("Result").getAsJsonObject().get("UserData").getAsJsonObject().get("Sign").getAsString();
//			Logger.verifyEquals(128, Sign.length(), "TokenSource验证Sign长度为128");
			Thread.sleep(3000);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lab.setClientId(ip2);
			lab.setTokenSource("app");
			lac2.setData(lab);
			lac2.callService();
			Logger.verifyEquals("true", lac2.getString("Success"), "验证登陆成功");
			
			
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> deviceAuth2 = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyEquals(200, deviceAuth2.get("AuthStatus"), "验证认证信息成功");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_006() {
		Logger.start(true,"双重认证开启设备认证成功JIRACONN-2522");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip =TestDataManager.getRandomIp();
			String ip2 =TestDataManager.getRandomIp();
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId=uc.getUserid();
			String UserName=  urb.getLoginId();
			String deviceId = urb.getDeviceId();
			String clientId = deviceId+"client";
//			int userId = 4460;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkDeviceLoginHistory(deviceId,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			
			Logger.comment("如果此设备已认证过，先进行删除");
			authWapper.deleteDeviceData(userId, deviceId);
			
			Logger.comment("设备登陆，AUTH_DEVICE_OPEN状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN);
			Logger.comment("设备登陆，isAppAppDeviceOpen状态是:"+LoginSafeConfiguration.isAppAppDeviceOpen);
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setClientIp(ip2);
			lab.setSourceType(SOURCETYPE);
			lab.setDeviceId(deviceId);
			lab.setClientId(clientId);
			lac.setData(lab);
			lac.callService();
			Thread.sleep(1000);
			Map<String, Object> deviceAuth = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyNotNull(deviceAuth, "认证区域认证信息被写入数据库");
			//这里需要看风控开关
//			Logger.verifyEquals(0, deviceAuth.get("AuthStatus"), "验证认证状态为未认证");
			AuthCallService.setSecurityQuestion(userId);
			AuthCallService.setSecurity(userId, true);
			
			Logger.comment("第一次认证失败");
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(false);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			LoginSafeConfiguration.checkAuthStatus(false, deviceauthstatusrequestdtoCall);
			
			
			Logger.comment("第二次认证成功");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoBean.setVerifySecurityQuestion(true);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			
			Thread.sleep(3000);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lab.setClientId(ip2);
			lac2.setData(lab);
			lac2.callService();
			Logger.verifyEquals("true", lac2.getString("Success"), "验证登陆成功");
			
			
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> deviceAuth2 = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyEquals(200, deviceAuth2.get("AuthStatus"), "验证认证信息成功");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_007() {
		Logger.start(false,"双重认证开启VerifySecurityQuestion未传设备认证失败JIRACONN-2522");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip =TestDataManager.getRandomIp();
			String ip2 =TestDataManager.getRandomIp();
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId=uc.getUserid();
			String UserName=  urb.getLoginId();
			String deviceId = urb.getDeviceId();
			String clientId = deviceId+"client";
//			int userId = 4460;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkDeviceLoginHistory(deviceId,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Thread.sleep(2000);
			Logger.comment("如果此设备已认证过，先进行删除");
			authWapper.deleteDeviceData(userId, deviceId);
			
			Logger.comment("设备登陆，AUTH_DEVICE_OPEN状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN);
			Logger.comment("设备登陆，isAppAppDeviceOpen状态是:"+LoginSafeConfiguration.isAppAppDeviceOpen);
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setClientIp(ip2);
			lab.setSourceType(SOURCETYPE);
			lab.setDeviceId(deviceId);
			lab.setClientId(clientId);
			lac.setData(lab);
			lac.callService();
			Thread.sleep(1000);
			Map<String, Object> deviceAuth = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyNotNull(deviceAuth, "认证区域认证信息被写入数据库");
			//这里需要看风控开关
//			Logger.verifyEquals(0, deviceAuth.get("AuthStatus"), "验证认证状态为未认证");
			AuthCallService.setSecurityQuestion(userId);
			AuthCallService.setSecurity(userId, true);
			
			Logger.comment("第一次认证失败");
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(false);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			LoginSafeConfiguration.checkAuthStatus(false, deviceauthstatusrequestdtoCall);
			
			
			
			Logger.comment("第二次认证");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			Logger.verifyEquals("false", deviceauthstatusrequestdtoCall.getString("Success"), "验证认证失败");
			Thread.sleep(3000);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lab.setClientId(ip2);
			lac2.setData(lab);
			lac2.callService();
			Logger.verifyEquals("false", lac2.getString("Success"), "验证登陆");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeviceAuthStatusRequestDto_008() {
		Logger.start(false,"双重认证开启VerifySecurityQuestion为false设备认证失败JIRACONN-2522");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip =TestDataManager.getRandomIp();
			String ip2 =TestDataManager.getRandomIp();
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId=uc.getUserid();
			String UserName=  urb.getLoginId();
			String deviceId = urb.getDeviceId();
			String clientId = deviceId+"client";
//			int userId = 4460;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkDeviceLoginHistory(deviceId,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			
			Logger.comment("如果此设备已认证过，先进行删除");
			authWapper.deleteDeviceData(userId, deviceId);
			
			Logger.comment("设备登陆，AUTH_DEVICE_OPEN状态是:"+LoginSafeConfiguration.AUTH_DEVICE_OPEN);
			Logger.comment("设备登陆，isAppAppDeviceOpen状态是:"+LoginSafeConfiguration.isAppAppDeviceOpen);
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setClientIp(ip2);
			lab.setSourceType(SOURCETYPE);
			lab.setDeviceId(deviceId);
			lab.setClientId(clientId);
			lac.setData(lab);
			lac.callService();
			Thread.sleep(1000);
			Map<String, Object> deviceAuth = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyNotNull(deviceAuth, "认证区域认证信息被写入数据库");
			//这里需要看风控开关
//			Logger.verifyEquals(0, deviceAuth.get("AuthStatus"), "验证认证状态为未认证");
			AuthCallService.setSecurityQuestion(userId);
			AuthCallService.setSecurity(userId, true);
			
			Logger.comment("第一次认证失败");
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(false);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			LoginSafeConfiguration.checkAuthStatus(false, deviceauthstatusrequestdtoCall);
			
			
			
			Logger.comment("第二次认证成功");
			deviceauthstatusrequestdtoBean=new DeviceAuthStatusRequestDtoBean();
			deviceauthstatusrequestdtoCall=new DeviceAuthStatusRequestDtoCall();
			deviceauthstatusrequestdtoBean.setClientId(clientId);
			deviceauthstatusrequestdtoBean.setDeviceId(deviceId);
			deviceauthstatusrequestdtoBean.setIp(ip2);
			deviceauthstatusrequestdtoBean.setLoginId(UserName);
			deviceauthstatusrequestdtoBean.setPassword("123456a");
			deviceauthstatusrequestdtoBean.setSource(SOURCETYPE);
			deviceauthstatusrequestdtoBean.setSuccess(true);
			deviceauthstatusrequestdtoBean.setVerifySecurityQuestion(false);
			deviceauthstatusrequestdtoCall.setData(deviceauthstatusrequestdtoBean);
			deviceauthstatusrequestdtoCall.callService();
			Logger.verifyEquals("false", deviceauthstatusrequestdtoCall.getString("Success"), "验证认证失败");
			Thread.sleep(3000);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lab.setClientId(ip2);
			lac2.setData(lab);
			lac2.callService();
			Logger.verifyEquals("false", lac2.getString("Success"), "验证登陆");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void checkDeviceLoginHistory(String deviceId, String dateTime) throws Exception{
		if(DELETELOGINHISTORY){
			blackLisWapper.deleteData(deviceId);
			mloginHistoryWapper.deleteByDeviceId(deviceId, dateTime);
		}
	}
}